﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using LosConn.BLL;
using Newtonsoft.Json;

namespace LosConn.Web.Handler
{
    /// <summary>
    /// PayHandler 的摘要说明
    /// </summary>
    public class PayHandler : IHttpHandler, IReadOnlySessionState
    {
        private BLL.Los_Pay bll = new BLL.Los_Pay();
        private BLL.Los_Retail bllRetail = new Los_Retail();
        public void ProcessRequest(HttpContext context)
        {
            String strResult = String.Empty;
            switch (context.Request["fun"])
            {

                case "f_0001": //新增金额，更新门市金额
                    strResult = UpdateGuestConfirm(context);
                    break;
                //case "f_0002": //审核
                //strResult = UpdateGuestCheck(context);
                //    break;
                //case "f_0003": //确认
                //strResult = UpdateGuestConfirm(context);
                //break;
                //case "f_0004": //新增产品类别
                //    strResult = AddType(context);
                //    break;
                //case "f_0005": //修改产品类别
                //    strResult = UpdateType(context);
                //    break;
                //case "f_0006": //假删除产品类别
                //    strResult = UpdateTypeStatus(context);
                //    break;
                default:
                    break;
            }

            context.Response.Write(strResult);
            context.Response.End();
        }

        #region 私有方法
        /// <summary>
        /// 新增金额，更新门市金额
        /// </summary>
        private String UpdateGuestConfirm(HttpContext context)
        {
            Model.Los_Pay model = JsonConvert.DeserializeObject<Model.Los_Pay>(context.Request["data"]);
            model.Pay_AddDate = DateTime.Now;
            model.Pay_UserID = Convert.ToInt32(context.Session["UserID"]);
            model.Pay_UserName = context.Session["UserName"].ToString();
            if (bll.AddPay(model) > 0)
            {
                Model.Los_Retail modelRetail = new Model.Los_Retail();
                modelRetail.Retail_ID = Convert.ToInt32(model.Pay_PayRetailID);
                modelRetail.Retail_Money = model.Pay_Money;
                bllRetail.AddPrice(modelRetail);
                return "{" + WebClass.RESULT_CODE_SUCCESS + "," + WebClass.RESULT_INFO + "\"" + WebClass.RESULT_SUCCESS_LAN + "\"}";
            }
            else
            {
                return "{" + WebClass.RESULT_CODE_ERROR + "," + WebClass.RESULT_INFO + "\"" + WebClass.RESULT_ERROR_LAN + "\"}";
            }
        }
        #endregion

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}